package example

import "gitee.com/youbeiwuhuan/gin-practice/go-enums/emums"

var hobyEnumMap map[string]string

type hobyEnumDef struct {
	Badminton  string
	Basketball string
	Football   string
}

func (c hobyEnumDef) Description() string {
	return "个人爱好"
}

// Values  返回一个包含所有枚举值的切片
func (c hobyEnumDef) Values() []string {
	return []string{c.Badminton, c.Basketball, c.Football}
}

// EnumItems 返回一个包含所有枚举值的切片
func (c hobyEnumDef) EnumItems() []emums.EnumItem[string] {
	sl := make([]emums.EnumItem[string], len(hobyEnumMap), len(hobyEnumMap))
	for k, v := range hobyEnumMap {
		sl = append(sl, emums.EnumItem[string]{Val: k, Label: v})
	}
	return sl
}

// Check 检查val是否枚举中一项
func (c hobyEnumDef) Check(val string) bool {
	_, ok := hobyEnumMap[val]
	return ok
}

// GetLabel  由val获取枚举值的描述
func (c hobyEnumDef) GetLabel(val string) (string, bool) {
	value, ok := hobyEnumMap[val]
	return value, ok
}

// ValueOf 根据名称返回对应的枚举值
func (c hobyEnumDef) ValueOf(label string) (string, bool) {
	for k, v := range hobyEnumMap {
		if v == label {
			return k, true
		}
	}

	return "", false
}

var HobyEnum = hobyEnumDef{
	Badminton:  "badminton",
	Basketball: "basketball",
	Football:   "football",
}

func init() {
	hobyEnumMap = make(map[string]string)
	hobyEnumMap[HobyEnum.Badminton] = "羽毛球"
	hobyEnumMap[HobyEnum.Basketball] = "篮球"
	hobyEnumMap[HobyEnum.Football] = "足球"

	//emums.RegistEnum[string]("HobyEnum", HobyEnum)
}
